#pragma once
#include "common.h"
#include <mutex>
#include <thread>
#include "ThreadCache.h"
#include "CenterCache.h"

class ThreadCache
{
public:
    void *Allocation(size_t size);

    void Dealloction(void *ptr, size_t size);

    // 从中心缓存获取一定数量的链表结点放入_freelist[index]中，并返回一个结点。
    void *FetchMemoryFromCenterCache(size_t index, size_t size);

    void Destroy();

private:
    FreeList _freelist[MAX_LIST];
};

#ifdef _WIN32
#define THREAD_LOCAL __declspec(thread)
#else
#define THREAD_LOCAL __thread
#endif

static THREAD_LOCAL ThreadCache *PTLSthreadCache = nullptr;
